<%@ page language="java" pageEncoding="UTF-8" import="com.chinapost.util.AuthUtil"%>
<%@ taglib prefix="my" uri="/WEB-INF/tlds/permission.tld" %>
<%
	AuthUtil authUtil = new AuthUtil(session);
%>
<script type="text/javascript">
	var wdxx_datagrid;
	$(function() {
		wdxx_datagrid = $('#wdxx_manager_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/wdxxAction!datagrid.action',
			pagination : true,
			pageSize : 20,
			pageList : [  10, 20, 30, 40, 50 ],
			border : false,
			fit : true,
			fitColumns : true,
			idField : 'cid',
			sortName : 'cmodifydate',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : true,
			columns : [ [ {
				title : '编号',
				field : 'cid',
				width : 100,
				align : "center",
				checkbox : true
			}, {
				title : '网点名称',
				field : 'cname',
				align : "center",
				width : 140
			}, {
				title : '所属机构名',
				field : 'deptName',
				align : "center",
				width : 120
			}, {
				title : '网点地址',
				field : 'caddress',
				align : "center",
				width : 140
			}, {
				title : '网点类型',
				field : 'ctype',
				align : "center",
				width : 60,
				formatter : function(value, row, index) {
					switch (value) {
					case 1:
						return "储蓄网点";
						break;
					case 2:
						return "营业网点";
						break;
					case 3:
						return "委代办网点";
						break;
					}
				}
			}, {
				title : '联系电话',
				field : 'cphone',
				align : "center",
				width : 80
			}, {
				title : '员工总数',
				field : 'czrs',
				align : "center",
				width : 60
			}, {
				title : '台席数量',
				field : 'ctx',
				align : "center",
				width : 60
			}, {
				title : '创建时间',
				field : 'ccreatedate',
				align : "center",
				width : 80
			}, {
				title : '修改时间',
				field : 'cmodifydate',
				align : "center",
				width : 80
			}, {
				title : '网点地图',
				field : 'cwd',
				align : "center",
				width : 80,
				formatter : function(value, row, index) {
					if (row.cjd != null && row.cwd != null) {
						return '<span class="icon-marker" style="display:inline-block;vertical-align:middle;width:16px;height:16px;"></span><a href="javascript:void(0);" onclick="wdxxMap(' + index + ');">查看地图</a>';
					} else {
						return '暂无地图';
					}
				}
			}, {
				field : 'action',
				title : '操作',
				width : 100,
				align : 'center',
				formatter : function(value, row, index) {
					var str='';
                	<%if (authUtil.isAuth("/wdxxAction!wdxxEdit.action")){%>
                	str += sy.fs('<img onclick="wdxxEdit(\'{0}\');" src="{1}" style="cursor: pointer;" title="修改"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/pencil.png');
                	<%}%>
                	<%if (authUtil.isAuth("/wdxxAction!delete.action")){%>
                	str += sy.fs('<img onclick="wdxxDelete(\'{0}\');" src="{1}" style="cursor: pointer;" title="删除"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/no.png');
                	<%}%>
                	return str;
				}
			} ] ],
			toolbar : '#wdxx_toolbar'
		});
		$('#wdxx_manager_dept').val('${sessionInfo.deptid}');
	});

	function wdxxEdit(cid) {
		if (cid != undefined) {
			$('#wdxx_manager_datagrid').datagrid('unselectAll');
			$('#wdxx_manager_datagrid').datagrid('selectRecord', cid);
		}
		var rows = $('#wdxx_manager_datagrid').datagrid('getSelected');
		var p = parent.sy.dialog({
			title : '网点信息编辑',
			iconCls : 'icon-edit',
			href : '${pageContext.request.contextPath}/wdxxAction!wdxxEdit.action',
			width : 660,
			height : 460,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/wdxxAction!edit.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								wdxx_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				var f = p.find('form');
				f.form('load', rows);
				var mypcas = new PCAS('wdxx_edit_province', 'wdxx_edit_cds', 'wdxx_edit_cqx');
				mypcas.SetValue('江西省', rows.cds, rows.cqx);
			}
		});
	};
	function wdxxAppend() {
		var p = parent.sy.dialog({
			title : '添加网点记录',
			iconCls : 'icon-append',
			href : '${pageContext.request.contextPath}/wdxxAction!wdxxAdd.action',
			width : 660,
			height : 460,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/wdxxAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								wdxx_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ]
		});
	}
	function wdxxRemove() {
		var rows = wdxx_datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '是否删除当前所选记录？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].cid);
					}
					$.ajax({
						url : '${pageContext.request.contextPath}/wdxxAction!delete.action',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							wdxx_datagrid.datagrid('load');
							$('#wdxx_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
							parent.sy.messagerShow({
								title : '提示',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请选择要删除的记录！', 'error');
		}
	};

	function wdxxDelete(cid) {
		$('#wdxx_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('#wdxx_manager_datagrid').datagrid('checkRow', $('#wdxx_manager_datagrid').datagrid('getRowIndex', cid));
		wdxxRemove();
	}

	function wdxxMap(rowIndex) {
		var rows = wdxx_datagrid.datagrid('getRows');
		var row = rows[rowIndex];
		var p = parent.sy.dialog({
			title : '网点地图',
			iconCls : 'icon-marker',
			href : '${pageContext.request.contextPath}/wdxxAction!wdxxMap.action?cid=' + row.cid,
			width : 800,
			height : 600,
			buttons : [ {
				text : '关闭',
				iconCls : 'icon-exit',
				handler : function() {
					p.dialog('close');
				}
			} ]
		});
	};

	function wdxxImport() {
		var p = parent.sy.dialog({
			title : '导入网点基础数据',
			iconCls : 'icon-import',
			href : '${pageContext.request.contextPath}/wdxxAction!wdxxImport.action',
			width : 510,
			height : 300,
			buttons : [ {
				text : '导入',
				iconCls : 'icon-accept',
				handler : function() {
					$.ajaxFileUpload({
						url : 'uploadFileAction!upload.action',//用于文件上传的服务器端请求地址  
						secureuri : false,//一般设置为false  
						fileElementId : 'wdxx_import_file',//文件上传空间的id属性  <input type="file" id="file" name="file" />  
						dataType : 'text',//返回值类型 json，text  
						success : function(d, status) //服务器成功响应处理函数  
						{
							var json = $.parseJSON(d);
							if (json.state) {
								$.messager.progress({
									text : '正在处理，请稍候...',
									interval : 100
								});
								$.post("wdxxAction!addWdxxs.action", {
									filename : json.filename,
									deptId : $('#wdxx_import_dept').combotree('getValue')
								}, function(rsp) {
									if (rsp.success) {
										wdxx_datagrid.datagrid('reload');
										p.dialog('close');
									}
									$.messager.progress('close');
									parent.sy.messagerAlert('提示', rsp.msg, 'info');
								}, "JSON");
							} else {
								$.messager.progress('close');
								parent.sy.messagerShow({
									msg : json.msg,
									title : '提示'
								});
							}
						},
						error : function(data, status, e)//服务器响应失败处理函数  
						{
							parent.sy.messagerAlert('错误', e, 'error');
						}
					});
				}
			} ]
		});
	};


	function _searchWdxx() {
		wdxx_datagrid.datagrid('load', sy.serializeObject($('#wdxx_search_form')));
		wdxx_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
	function _cleanSearchWdxx() {
		$('#wdxx_search_form  input[name="cname"]').val('');
		$('#wdxx_manager_dept').combotree('setValue','${sessionInfo.deptid}');
		wdxx_datagrid.datagrid('load', sy.serializeObject($('#wdxx_search_form')));
		wdxx_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
</script>




<div class="easyui-layout" data-options="fit:true" style="overflow: hidden;">
	<div data-options="region:'north',title:'查询网点',iconCls:'icon-search'" style="height: 80px;padding:5px;overflow: hidden;">
		<div style="padding:5px">
			<form method="post" id="wdxx_search_form" style="display:inline">
			<span>所属机构：</span>
			<input id="wdxx_manager_dept" class="easyui-combotree" name="deptId" data-options="line:true,url:'deptAction!do_combotree.action',panelHeight:280,required:true,editable:false,idField:'id',textField:'text',parentField:'pid'" style="width:180px"/>&nbsp;&nbsp;
				<span> 网点名称：</span> <input type='text' name='cname' />
			</form>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="_searchWdxx();">查询</a>&nbsp; <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onClick="_cleanSearchWdxx();">清空</a>
		</div>
	</div>
	<div data-options="region:'center',title:'网点列表',border:true,iconCls:'icon-application'" style="overflow: hidden;">
		<table id="wdxx_manager_datagrid"></table>
	</div>
</div>
<div id="wdxx_toolbar" style="display: none;" >
<table  class="toolbar" >
	<tr>
		<my:per url="/wdxxAction!wdxxAdd.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-append',plain:true" onclick="wdxxAppend();">新增</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/wdxxAction!delete.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-delete',plain:true" onclick="wdxxRemove()">批量删除</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/wdxxAction!wdxxImport.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-import',plain:true" onclick="wdxxImport()">批量导入</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
	</tr>
</table>
</div>
